<?php
namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Service\PowerService;
use App\Http\Requests\NodeRequest;
use App\Models\Node;

class PowerController extends CommentController
{
	private $_power;
    private $_nodeModel;

	public function __construct()
	{
        $this->_nodeModel = Node::getInstance();
		$this->_power = PowerService::getInstance();
	}

	public function index()
	{
        $list = $this->_nodeModel->paginate(15);
        $count = $this->_nodeModel->countNode();
		return view('admin.power.index', ['list'=>$list, 'count'=>$count]);
	}

	/**
     * 添加页面
     * @author 朱旭
     */
	public function create()
    {
        return view('admin.power.create');
    }

    /**
     * 添加方法
     * @author 朱旭
     */
    public function store(NodeRequest $request)
    {
        return $this->returnJson($this->_power->addToPower($request));
    }

     /**
     * 显示指定文章
     *
     * @param int $id
     * @return Response
     */
    public function show($id)
    {
        
    }

    /**
     * 显示编辑指定文章的表单页面
     *
     * @param int $id
     * @return Response
     */
    public function edit($id)
    {
        $data = $this->_nodeModel->showNode($id);
    	return view('admin.power.edit', ['data'=>$data]);
    }

    /**
     * 在存储器中更新指定文章
     *
     * @param Request $request
     * @param int $id
     * @return Response
     */
    public function update(NodeRequest $request, $id)
    {
        return $this->returnJson($this->_power->editPower($request, $id));
    }

    /**
     * 从存储器中移除指定文章
     *
     * @param int $id
     * @return Response
     */
    public function destroy($id)
    {
        return $this->returnJson($this->_power->delete($id));
    }

    /**
     * 更改状态
     * @author 朱旭
     */
    public function status($id)
    {
        return $this->returnJson($this->_power->status($id));
    }
}